package com.example.gss.ServiceImpl;

import com.example.gss.entity.ResearchAchievement;
import com.example.gss.mapper.ResearchAchievementMapper;
import com.example.gss.Service.ResearchAchievementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ResearchAchievementServiceImpl implements ResearchAchievementService {

    @Autowired
    private ResearchAchievementMapper achievementMapper;

    @Override
    public List<ResearchAchievement> getAll() {
        return achievementMapper.selectAll();
    }

    @Override
    public ResearchAchievement getById(String id) {
        return achievementMapper.selectById(id);
    }

    @Override
    public List<ResearchAchievement> getByStudentId(String studentId) {
        return achievementMapper.selectByStudentId(studentId);
    }

    @Override
    public int save(ResearchAchievement achievement) {
        if (achievement.getAchievementId() == null) {
            // 生成唯一ID（实际项目中建议使用UUID）
            // achievement.setAchievementId(UUID.randomUUID().toString());
            return achievementMapper.insert(achievement);
        } else {
            return achievementMapper.update(achievement);
        }
    }

    @Override
    public int update(ResearchAchievement achievement) {
        return achievementMapper.update(achievement);
    }

    @Override
    public int delete(String id) {
        return achievementMapper.delete(id);
    }
}